<?php

namespace app\common\model;

use think\Model;

/**
 * Auth权限管理-用户组管理模型
 * Class Group
 * @package app\common\model
 */
class Group extends Model
{
	//数据表
	protected $table = 'authgroup';
	//主键
	protected $pk = 'id';

	//添加
	public function add($data)
	{
		$data['rules'] = isset($data['rules']) ? implode(',', $data['rules']) : '';
		$res = $this->validate(true)->save($data);
		if ($res === false) {
			return ['valid' => 0, 'msg' => $this->getError()];
		} else {
			return ['valid' => 1, 'msg' => '添加成功'];
		}
	}

	//编辑
	public function edit($data)
	{
		$data['rules'] = isset($data['rules']) ? implode(',', $data['rules']) : '';
		$res = $this->validate(true)->save($data, [$this->pk => $data['id']]);
		if ($res === false) {
			return ['valid' => 0, 'msg' => $this->getError()];
		} else {
			return ['valid' => 1, 'msg' => '编辑成功'];
		}
	}
}
